package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.json.JSONUtil;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.SqfwExcelCreateCommonBO;
import com.budwk.app.sqfwDoc.dto.TemplateCodeUpdateDTO;
import com.budwk.app.sqfwV2.service.dayingRoad.DaYingLuRedWhiteRecordExcelService;
import com.budwk.app.sqfwV2.service.dayingRoad.DaYingLuRedWhiteRecordPdfService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.openapi.annotation.ApiResponses;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import com.budwk.starter.security.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

import java.util.List;

/**
 * @BelongsProject: dfxy-shequ
 * @Author: yangweimin
 * @CreateTime: 2024-01-30  16:11
 * @Description: 大营路红白事备案
 */
@IocBean
@At("/platform/sqfw/daYingLuRedWhiteRecord")
@ApiDefinition(tag = "大营路")
@Slf4j
public class DaYingLuRedWhiteRecordController {

    @Inject
    private DaYingLuRedWhiteRecordPdfService daYingLuRedWhiteRecordPdfService;
    @Inject
    private DaYingLuRedWhiteRecordExcelService daYingLuRedWhiteRecordExcelService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "创建pdf")
    @ApiResponses
    @SLog(tag = "创建pdf", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> createPdf(@Param("..") TemplateCodeUpdateDTO templateCodeUpdateDTO) {
        log.info("大营路红白事备案：{}", JSONUtil.toJsonStr(templateCodeUpdateDTO));
        String userId = SecurityUtil.getUserId();
        templateCodeUpdateDTO.getFormSummary().setCreateBy(userId);
        daYingLuRedWhiteRecordPdfService.generatePdfAndMessage(userId, templateCodeUpdateDTO);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "创建Excel")
    @ApiResponses
    @SLog(tag = "创建Excel", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> createExcel(@Param("excelConfigList") List<ExcelCreateConfig> excelConfigList,
                                 @Param("sqfwIdList") List<String> sqfwIdList,
                                 @Param("startTime") String startTime,
                                 @Param("endTime") String endTime) {
        String userId = SecurityUtil.getUserId();
        List<GenerateExcelUrlVO> vos = daYingLuRedWhiteRecordExcelService.createExcel(excelConfigList, userId, sqfwIdList, startTime, endTime);
        return Result.success(vos);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "红白事pdf合集下载")
    @ApiResponses
    @SLog(tag = "红白事pdf合集下载", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> downPdfList(@Param("excelConfigList") List<ExcelCreateConfig> excelConfigList,
                                 @Param("sqfwIdList") List<String> sqfwIdList,
                                 @Param("startTime") String startTime,
                                 @Param("endTime") String endTime) {
        List<GenerateExcelUrlVO> vos = daYingLuRedWhiteRecordPdfService.downPdfList(excelConfigList, sqfwIdList, startTime, endTime);
        return Result.success(vos);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "获取红白事数据")
    @ApiResponses
    @SaCheckLogin
    public Result<?> list(@Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize,
                          @Param("type") String type, @Param("fillDate") String fillDate) {
        return Result.data(daYingLuRedWhiteRecordPdfService.list(pageNo, pageSize, type));
    }
}
